from django.contrib import admin
from .models import Comment, Like, Bookmark


@admin.register(Comment)
class CommentAdmin(admin.ModelAdmin):
    """评论管理后台"""
    list_display = ['id', 'author', 'story', 'content_preview', 'likes', 'created_at']
    list_filter = ['created_at']
    search_fields = ['content', 'author__name', 'story__title']
    ordering = ['-created_at']
    readonly_fields = ['likes', 'created_at']
    
    def content_preview(self, obj):
        """内容预览"""
        return obj.content[:50] + '...' if len(obj.content) > 50 else obj.content
    content_preview.short_description = '内容预览'


@admin.register(Like)
class LikeAdmin(admin.ModelAdmin):
    """点赞管理后台"""
    list_display = ['id', 'user', 'story', 'comment', 'created_at']
    list_filter = ['created_at']
    search_fields = ['user__name', 'story__title']
    ordering = ['-created_at']
    readonly_fields = ['created_at']


@admin.register(Bookmark)
class BookmarkAdmin(admin.ModelAdmin):
    """收藏管理后台"""
    list_display = ['id', 'user', 'story', 'created_at']
    list_filter = ['created_at']
    search_fields = ['user__name', 'story__title']
    ordering = ['-created_at']
    readonly_fields = ['created_at']
